<include file="Public:header" />
<div class="page-member subpage">
    <div class="form-header">
        <div>
            <div class="line1">
                <div class="fl"><h3>直管公房申请详情 / {$menmian.house_addr}</h3></div>
                <div class="fr hidden">
                    <form class="search-form" method="post" action="">
                        <input name="field" value="{$context.field}" type="hidden" />
                        <input name="value" value="{$context.value}" type="hidden" />
                        <input name="page" value="{$context.page}" type="hidden" />
                        <input name="order_field" value="{$context.order_field}" type="hidden" />
                        <input name="order_sort" value="{$context.order_sort}" type="hidden" />
                        <input name="offset" value="{$context.offset}" type="hidden" />
                        <input name="id" value="{$context.id}" type="hidden" />
                    </form>
                </div>
            </div>
            <div class="line2">
                <!-- 编辑按钮组 -->
                <div class="fl form-btn-group btn-group-edit">
                    <if condition="$menmian.state eq '待签订合同'">
                        <in name="$x|default='02-04-05'" value="$rightsCode">
                            <button onclick="showDialog('dialog-contact');" class="btn-save btn-highlight">签订合同</button>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">签订合同</button>
                        </in>
                        <else />
                        <button disabled="disabled" class="btn-save btn-disable">签订合同</button>
                    </if>
                    <span>或</span>
                    <in name="$x|default='02-04-02'" value="$rightsCode">
                        <a onclick="action_edit();" class="linkBtn btn-abort" href="javascript:void(0);">编辑</a>
                        <else />
                        <a onclick="history.back(-1);" class="linkBtn btn-abort" href="javascript:void(0);">返回</a>
                    </in>
                </div>
                <!-- 保存按钮组 -->
                <div class="fl form-btn-group btn-group-save hidden">
                    <button onclick="action_save();" class="btn-save btn-highlight">保 存</button>
                    <span>或</span>
                    <a class="linkBtn btn-abort" onclick="action_abort();" href="javascript:void(0);">放弃</a>
                </div>
                <div class="fl form-btn-more">
                    <button class="btn-normal btn-more">
                        更多操作<i class="drop-down"></i>
                    </button>
                    <ul class="more-action hidden">
                        <in name="$x|default='02-04-02'" value="$rightsCode">
                            <li><a onclick="action_del2();" href="javascript:void(0);">删 除</a></li>
                        </in>
                    </ul>
                </div>
                <div class="fr form-search-count">
                    <span class="index">{$context.index}/{$page.total}</span>
                    <button onclick="ItemJump({$page.prev.id}, {$page.prev.offset});" class="btn-normal">上一条</button>
                    <button onclick="ItemJump({$page.next.id}, {$page.next.offset});" class="btn-normal">下一条</button>
                </div>
            </div>
        </div>
    </div>
    <div class="form-box2">
        <div>
            <form id="menmianForm" method="post" action="">
                <!--表单相关原始信息存储-->
                <input type="hidden" name="old_name" value="{$menmian.name}" />
                <input type="hidden" name="old_zj" value="{$menmian.zj}" />
                <input type="hidden" name="old_mzj" value="{$menmian.mzj}" />
                <input type="hidden" name="old_size" value="{$menmian.size}" />
                <input type="hidden" name="old_yj" value="{$menmian.yj}" />
                <input type="hidden" name="old_gender" value="{$menmian.gender}" />
                <input type="hidden" name="old_resident_num" value="{$menmian.resident_num}" />
                <input type="hidden" name="old_addr" value="{$menmian.addr}" />
                <input type="hidden" name="old_idno" value="{$menmian.idno}" />
                <input type="hidden" name="old_phone" value="{$menmian.phone}" />
                <input type="hidden" name="old_remarks" value="{$menmian.remarks}" />
                <table class="form">
                    <tr>
                        <th width="15%">姓名<span class="hint">*</span></th>
                        <td width="35%" field="name">{$menmian.name}</td>
                        <th width="15%">性别</th>
                        <td width="35%" field="gender">{$menmian.gender}</td>
                    </tr>
                    <tr>
                        <th>联系电话</th>
                        <td field="phone">{$menmian.phone}</td>
                        <th>身份证号<span class="hint">*</span></th>
                        <td field="idno">{$menmian.idno}</td>
                    </tr>
                    <tr>
                        <th>居住人口<span class="hint">*</span></th>
                        <td field="resident_num">{$menmian.resident_num}</td>
                        <th>现居住地址</th>
                        <td field="addr">{$menmian.addr}</td>
                    </tr>
                    <tr>
                        <th>房源地址<span class="hint">*</span></th>
                        <td field="house_addr">{$menmian.house_addr}</td>
                        <th>小区名称<span class="hint">*</span></th>
                        <td field="community">{$menmian.community}</td>
                    </tr>
                    <tr>
                        <th>月租金</th>
                        <td field="zj">{$menmian.zj}</td>
                        <th>市场月租金</th>
                        <td field="mzj">{$menmian.mzj}</td>
                    </tr>
                    <tr>
                        <th >面积</th>
                        <td field="size">{$menmian.size}</td>
                        <th >押金</th>
                        <td field="yj">{$menmian.yj}</td>
                    </tr>
                    <tr>
                        <th >合同编号</th>
                        <td field="contact_no">{$menmian.contact_no}</td>
                        <th >合同签订日期</th>
                        <td field="contact_date">{$menmian.contact_date}</td>
                    </tr>
                    <tr>
                        <th >备注</th>
                        <td field="remarks">{$menmian.remarks}</td>
                    </tr>
                    <tr>
                        <td></td><td></td><td></td><td></td>
                    </tr>
                    <tr>
                        <th>电子证件</th>
                        <td colspan="3">
                            <table>
                                <tr>
                                    <td>
                                        <neq name="menmian.sfzImg" value="">
                                            <img name="sfzImg" style="width:120px;height:80px;" class="img-upload img-small" src="{$menmian.sfzImg}" />
                                            <else />
                                            <img name="hkbImg" style="width:120px;height:80px;" class="img-upload" src="__IMG__/index/sfzzm.png" />
                                        </neq>
                                    </td>
                                    <td>
                                        <neq name="menmian.hkbImg" value="">
                                            <img name="hkbImg" style="width:120px;height:80px;" class="img-upload img-small" src="{$menmian.hkbImg}" />
                                            <else />
                                            <img name="hkbImg" style="width:120px;height:80px;" class="img-upload" src="__IMG__/index/hkb.png" />
                                        </neq>
                                    </td>
                                    <td>
                                        <neq name="menmian.yyzzImg" value="">
                                            <img name="yyzzImg" style="width:120px;height:80px;" class="img-upload img-small" src="{$menmian.yyzzImg}" />
                                            <else />
                                            <img name="yyzzImg" style="width:120px;height:80px;" class="img-upload" src="__IMG__/index/yyzz.png" />
                                        </neq>
                                    </td>
                                </tr>
                            </table>
                            <input name="upload" class="hidden" type="file" />
                            <input name="sfzImg" type="hidden" value="{$menmian.sfzImg}" />
                            <input name="hkbImg" type="hidden" value="{$menmian.hkbImg}" />
                            <input name="yyzzImg" type="hidden" value="{$menmian.yyzzImg}" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<div class="dialog dialog-contact hidden">
    <div class="box" style="margin-top:40px;height:520px;width:800px;">
        <div class="title">
            <h4 class="fl">签订合同对话框</h4>
            <span class="fr"><a href="#" onclick="action_CloseContactDlg();">关闭</a></span>
        </div>
        <div class="form-box2" style="margin: 0;">
            <div>
                <table class="form">
                    <tr>
                        <th width="15%">业务编号<span class="hint">*</span></th>
                        <td width="35%"><input disabled="disabled" name="ywno" type="text" value="{$menmian.no}" /> </td>
                        <th width="15%">合同类型<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="type" type="text" value="{$menmian.house_type}" /></td>
                    </tr>
                    <tr>
                        <th>房源地址<span class="hint">*</span></th>
                        <td>
                            <input class="hidden" name="community" type="text" value="{$menmian.community}" />
                            <input class="hidden" name="fwbh" type="text" value="{$menmian.house_no}" />
                            <input class="disabled" name="fwdz" type="text" disabled="disabled" value="{$menmian.house_addr}" />
                        </td>
                        <th>房源面积<span class="hint">*</span></th>
                        <td><input class="disabled" name="size" disabled="disabled" type="text" value="{$menmian.size}" /> </td>
                    </tr>
                    <tr>
                        <th>标准月租金(元)<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="zj" type="text" value="{$menmian.zj}" /> </td>
                        <th>市场月租金(元)<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="mzj" type="text" value="{$menmian.mzj}" /> </td>
                    </tr>
                    <tr>
                        <th>甲方<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="jiafang" type="text" value="{$menmian.jiafang|default=C('CONTACT_JIAFANG')}" /> </td>
                        <th>乙方<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="yifang" type="text" value="{$menmian.name}" /> </td>
                    </tr>
                    <tr>
                        <th>合同开始日期<span class="hint">*</span></th>
                        <td><input class="disabled" name="ksrq" type="text" value="{$contact.ksrq|default=$contactDate['start']}" style="border:1px solid red;" /> </td>
                        <th>合同结束日期<span class="hint">*</span></th>
                        <td><input class="disabled" name="jsrq" type="text" value="{$contact.jsrq|default=$contactDate['end']}" style="border:1px solid red;" /> </td>
                    </tr>
                    <tr>
                        <th>押金(元)<span class="hint">*</span></th>
                        <td><input name="yj" type="text" disabled="disabled" value="{$menmian.yj|default=C('CONTACT_YAJIN')}" /> </td>
                        <th>低保人口<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="dibaork" type="text" value="{$contact.dibaork|default=0}" /> </td>
                    </tr>
                    <tr>
                        <th>减免类型<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="derate_type" type="text" value="无租金减免" /> </td>
                        <th>减免金额(元)<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="derate_money" type="text" value="0.00" /> </td>
                    </tr>
                    <tr>
                        <th>应缴租金<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="total2" type="text" value="{$contact.total}" /> </td>
                        <th>减免后应缴租金<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="total" type="text" value="{$contact.total}" /> </td>
                    </tr>
                    <tr>
                        <th>甲方法定代表人<span class="hint">*</span></th>
                        <td><input name="jffr" type="text" value="{$menmian.jffr|default=C('CONTACT_FAREN')}" /> </td>
                        <th>乙方身份证身份证<span class="hint">*</span></th>
                        <td><input class="disabled" disabled="disabled" name="yfsfz" type="text" value="{$menmian.idno}" /> </td>
                    </tr>
                    <tr>
                        <th>甲方经办人<span class="hint">*</span></th>
                        <td><input name="jfjbr" type="text" value="{$menmian.jfjbr|default=C('CONTACT_JINBAN')}" /> </td>
                        <th>乙方联系地址</th>
                        <td><input name="yfdz" type="text" value="{$menmian.addr}" /> </td>
                    </tr>
                    <tr>
                        <th>甲方联系电话<span class="hint">*</span></th>
                        <td><input name="jfdh" type="text" value="{$menmian.jfdh|default=C('CONTACT_PHONE')}" /> </td>
                        <th>乙方电话<span class="hint">*</span></th>
                        <td><input name="yfdh" type="text" value="{$menmian.phone}" /> </td>
                    </tr>
                    <tr style="vertical-align: top;">
                        <th>签订日期<span class="hint">*</span></th>
                        <td><input name="ctime" type="text" value="{$menmian.ctime2|default=time()|date='Y/m/d',###}" /> </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <input type="hidden" name="summary" value="{$contact.total2}" />
                            <button class="btn btn-highlight" onclick="action_CreateContact();">提交</button>
                            <span>或</span>
                            <a href="#" onclick="action_CloseContactDlg();" class="linkBtn">放弃</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
<link type="text/css" href="__JS__/datetimepicker/pikaday.css" rel="stylesheet">
<script src="__JS__/datetimepicker/pikaday.min.js" type="text/javascript"></script>
<link  href="__JS__/viewer/viewer.min.css" rel="stylesheet">
<script src="__JS__/viewer/viewer.min.js"></script>
<script>

    $(".img-small").viewer(); //开启图片查看器功能；

    function action_CreateContact(){

        var summary = $("input[name=summary]").val();
        alert("本次共需要缴纳租金+押金共计："+summary+"元");

        var data = {
            "id": $("input[name=id]").val(),
            "derate_type": $("input[name=derate_type]").val(),
            "derate_money": $("input[name=derate_money]").val(),
            "ywno": $("input[name=ywno]").val(),
            "community": $("input[name=community]").val(),
            "type": $("input[name=type]").val(),
            "dibaork": $("input[name=dibaork]").val(),
            "jiafang": $("input[name=jiafang]").val(),
            "yifang": $("input[name=yifang]").val(),
            "fwbh": $("input[name=fwbh]").val(),
            "fwdz": $("input[name=fwdz]").val(),
            "size": $("input[name=size]").val(),
            "zj": $("input[name=zj]").val(),
            "mzj": $("input[name=mzj]").val(),
            "total": $("input[name=total]").val(),
            "total2": $("input[name=total2]").val(),
            "yj": $("input[name=yj]").val(),
            "ksrq": $("input[name=ksrq]").val(),
            "jsrq": $("input[name=jsrq]").val(),
            "jffr": $("input[name=jffr]").val(),
            "jfjbr": $("input[name=jfjbr]").val(),
            "jfdz": $("input[name=jfdz]").val(),
            "jfdh": $("input[name=jfdh]").val(),
            "yfsfz": $("input[name=yfsfz]").val(),
            "yfdw": $("input[name=yfdw]").val(),
            "yfdz": $("input[name=yfdz]").val(),
            "yfdh": $("input[name=yfdh]").val(),
            "ctime": $("input[name=ctime]").val(),
            "state": "已签订"
        };
        if(!data.ywno || !data.fwbh){
            alert("请填写有效的业务编号");
            $("input[name=ywno]").focus();
            return true;
        }
        if(parseFloat(data.size) <= 0){
            alert("房源面积输入有误，请检查房源:"+data.fwdz+"的房源面积是否设置正确");
            $("input[name=size]").focus();
            return true;
        }
        if(parseFloat(data.zj) <= 0){
            alert("标准月租金输入有误，请检查房源:"+data.fwdz+"的月租金是否设置正确");
            $("input[name=zj]").focus();
            return true;
        }
        if(parseFloat(data.mzj) <= 0){
            alert("市场月租金输入有误，请检查房源:"+data.fwdz+"的市场月租金是否设置正确");
            $("input[name=mzj]").focus();
            return true;
        }
        if(parseFloat(data.total2) <= 0){
            alert("应缴租金输入有误，请检查房源:"+data.fwdz+"的月租金是否设置正确");
            $("input[name=total2]").focus();
            return true;
        }
        $.ajax({
            url:"/admin/menmian/ajax_CreateContact",
            data: data, type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    location.href = '/admin/admin/ok?msg='+data.info;
                }else{
                    console.log(data.info);
                    alert(data.info);
                }
            }
        });
    }

    function action_CloseContactDlg(){
        $(".dialog-contact").hide();
    }

    var picker = new Pikaday(
            {
                field: document.getElementsByName('ksrq')[0],
                firstDay: 1,
                minDate: new Date('2015/01/01'),
                maxDate: new Date('2025/12/31'),
            });
    var picker = new Pikaday(
            {
                field: document.getElementsByName('jsrq')[0],
                firstDay: 1,
                minDate: new Date('2015/01/01'),
                maxDate: new Date('2025/12/31'),
            });
    $("input[name=ksrq]").change(function(){
        reCalRental();
    });
    $("input[name=jsrq]").change(function(){
        reCalRental();
    });
    function reCalRental(){
        var date1 = $("input[name=ksrq]").val();
        var date2 = $("input[name=jsrq]").val();
        if(!isDate(date1)){
            alert("合同开始日期不是有效的日期格式");
            $(this).focus();
            return false;
        }
        if(!isDate(date2)){
            alert("合同结束日期不是有效的日期格式");
            $(this).focus();
            return false;
        }
        var yj = parseFloat($("input[name=yj]").val());
        var zj = parseFloat($("input[name=zj]").val());
        var size = parseFloat($("input[name=size]").val());
        var dibaork = parseInt($("input[name=dibaork]").val());
        var zujing = calZujin(date1, date2, zj, size, dibaork);
        $("input[name=total]").val(zujing.toFixed(2));
        $("input[name=total2]").val(zujing.toFixed(2));
        $("input[name=summary]").val((zujing+yj).toFixed(2));
    }

    function dateRangeToFloat(date1, date2){
        var y1 = parseInt(date1.substr(0, 4));
        var y2 = parseInt(date2.substr(0, 4));
        var m1 = parseInt(date1.substr(5, 2));
        var m2 = parseInt(date2.substr(5, 2));
        var d1 = parseInt(date1.substr(8, 2));
        var d2 = parseInt(date2.substr(8, 2));
        if(y1>y2){
            alert("日期错误，开始年份不能大于结束年份");
            return false;
        }
        if(y1==y2 && m1>m2){
            alert("日期错误，开始月份不能大于结束月份");
            return false;
        }
        if(y1==y2 && m1==m2 && d1>=d2){
            alert("日期错误，开始日期不能大于结束日期");
            return false;
        }
        if(m2-m1==0){ //同年同月的情况
            return (y2-y1)*12 + Math.min((d2-d1+1)/30, 1);
        }else{
            return (y2-y1)*12 + Math.min(d2/30, 1) + m2-m1 - Math.min((d1-1)/30, 1);
        }
    }

    function calZujin(date1, date2, zujin, size, dibaork){
        var month = dateRangeToFloat(date1, date2);
        if(month!==false){
            if(dibaork*13>=size){ //低保人口享受面积大于房屋面积，则不要出房租
                return size*1.1*month;
            }
            //13平米每人内按1.1元每平米的价格计算
            var zj = (size-dibaork*13)*zujin/size + dibaork*13*1.1;
            return zj*month;
        }
    }

    function isDate(dateString){
        if(dateString.trim()=="")return true;
        var r=dateString.match(/^(\d{1,4})(\/)(\d{1,2})\2(\d{1,2})$/);
        if(r==null){
            alert("请输入格式正确的日期\n\r日期格式：yyyy/mm/dd\n\r例  如：2008/08/08\n\r");
            return false;
        }
        var d=new Date(r[1],r[3]-1,r[4]);
        var num = (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
        if(num==0){
            alert("请输入格式正确的日期\n\r日期格式：yyyy-mm-dd\n\r例  如：2008-08-08\n\r");
        }
        return (num!=0);
    }

    /**
     * 全局变量 fields
     */
    var fields = new Array("name", "zj", "mzj", "size", "yj", "gender", "resident_num", "addr", "idno", "phone", "remarks");
</script>
<script src="__JS__/menmian.js?v=0.3" type="text/javascript" ></script>
<include file="Public:footer" />
